home *** CD-ROM | disk | FTP | other *** search
/ Borland JBuilder 6 / jbuilder6.iso / Taiji Applet Pack v2.7 / Table / Table.class (.txt) < prev    next >
Encoding:
Java Class File  |  2001-11-06  |  8.9 KB  |  426 lines

  1. import java.applet.Applet;
  2. import java.awt.Color;
  3. import java.awt.Component;
  4. import java.awt.Container;
  5. import java.awt.Cursor;
  6. import java.awt.Font;
  7. import java.awt.Graphics;
  8. import java.awt.Label;
  9. import java.awt.LayoutManager;
  10. import java.awt.event.MouseEvent;
  11. import java.awt.event.MouseListener;
  12. import java.io.BufferedReader;
  13. import java.io.IOException;
  14. import java.io.InputStream;
  15. import java.io.InputStreamReader;
  16. import java.net.MalformedURLException;
  17. import java.net.URL;
  18. import java.net.URLEncoder;
  19.  
  20. public class Table extends Applet implements MouseListener {
  21.    // $FF: renamed from: wi int
  22.    private int field_0;
  23.    // $FF: renamed from: he int
  24.    private int field_1;
  25.    private int NCol;
  26.    private int NRow;
  27.    private String[][] data;
  28.    private Color backColor;
  29.    private Color backColor2;
  30.    private Color columnsColor;
  31.    private int mode;
  32.    private int heMax;
  33.    private int space = 10;
  34.    private int titleMode;
  35.    private int skip;
  36.    private String statusBarText;
  37.    private String link;
  38.    private int border;
  39.    private Color borderColor;
  40.    private int wspace;
  41.  
  42.    public String getAppletInfo() {
  43.       return "Name: Table\r\nAuthor: Taiji Software";
  44.    }
  45.  
  46.    public void register() {
  47.       try {
  48.          URL u = new URL("http://www.taijisoftware.com");
  49.          ((Applet)this).getAppletContext().showDocument(u, "_blank");
  50.       } catch (Exception e) {
  51.          System.out.println(e);
  52.          this.stop();
  53.       }
  54.    }
  55.  
  56.    public void init() {
  57.       String codeBase = null;
  58.  
  59.       try {
  60.          codeBase = (new URL(((Applet)this).getCodeBase().toString())).getHost();
  61.          System.out.println("Copyright 1999, 2001 Taiji Software(tm)\nYour domain name is : " + codeBase);
  62.          codeBase = codeBase.toUpperCase();
  63.       } catch (Exception var13) {
  64.       }
  65.  
  66.       if (!((Applet)this).getCodeBase().toString().toUpperCase().startsWith("FILE") || ((Applet)this).getParameter("debug") != null) {
  67.          String regCode = ((Applet)this).getParameter("registration_code");
  68.          if (regCode == null) {
  69.             regCode = ((Applet)this).getParameter("reg_domain");
  70.             if (regCode == null) {
  71.                this.register();
  72.             } else {
  73.                if (regCode.length() == codeBase.length() + 4 && !codeBase.startsWith("WWW.")) {
  74.                   codeBase = "WWW." + codeBase;
  75.                } else if (regCode.length() == codeBase.length() - 4 && codeBase.startsWith("WWW.")) {
  76.                   codeBase = codeBase.substring(4);
  77.                }
  78.  
  79.                char[] chars = new char[codeBase.length()];
  80.                codeBase.getChars(0, codeBase.length(), chars, 0);
  81.                String key = new String("haricot");
  82.                char[] chars2 = new char[key.length()];
  83.                key.getChars(0, key.length(), chars2, 0);
  84.  
  85.                for(int i = 0; i < codeBase.length(); ++i) {
  86.                   int j;
  87.                   if (i >= key.length()) {
  88.                      j = i - key.length() * (i / key.length());
  89.                   } else {
  90.                      j = i;
  91.                   }
  92.  
  93.                   chars[i] += chars2[j];
  94.                   chars[i] = (char)(chars[i] - chars[i] / 26 * 26 + 97);
  95.                }
  96.  
  97.                String res = new String(chars);
  98.                if (!res.equalsIgnoreCase(regCode)) {
  99.                   this.register();
  100.                }
  101.             }
  102.          } else if (!regCode.equals("settevercsedegnamiaj") && !regCode.equals("8078")) {
  103.             this.register();
  104.          }
  105.       }
  106.  
  107.       this.getParameters();
  108.  
  109.       try {
  110.          String s = "";
  111.          InputStream in = null;
  112.          in = (new URL(((Applet)this).getCodeBase(), ((Applet)this).getParameter("data_file"))).openStream();
  113.          BufferedReader br = new BufferedReader(new InputStreamReader(in));
  114.  
  115.          while((s = br.readLine()) != null) {
  116.             try {
  117.                if (this.NCol == 0) {
  118.                   int p;
  119.                   while((p = s.indexOf(",")) != -1) {
  120.                      ++this.NCol;
  121.                      s = s.substring(p + 1);
  122.                   }
  123.  
  124.                   ++this.NCol;
  125.                }
  126.  
  127.                ++this.NRow;
  128.             } catch (Exception var16) {
  129.             }
  130.          }
  131.  
  132.          br.close();
  133.       } catch (IOException e) {
  134.          System.out.println("data file read error !" + e);
  135.       }
  136.  
  137.       ((Component)this).setBackground(this.backColor);
  138.       int NRows = this.NRow;
  139.       if (this.titleMode == 1) {
  140.          NRows = this.NRow + 1;
  141.       } else if (this.titleMode == 2) {
  142.          NRows = this.NRow + 2;
  143.       }
  144.  
  145.       if (this.skip == 1) {
  146.          --NRows;
  147.       }
  148.  
  149.       this.data = new String[NRows][this.NCol];
  150.  
  151.       try {
  152.          String s = "";
  153.          InputStream in = null;
  154.          in = (new URL(((Applet)this).getCodeBase(), ((Applet)this).getParameter("data_file"))).openStream();
  155.          BufferedReader br = new BufferedReader(new InputStreamReader(in));
  156.          int i = 0;
  157.  
  158.          while(true) {
  159.             if (i == 0 && this.skip == 1) {
  160.                s = br.readLine();
  161.             }
  162.  
  163.             if (i == 0 && this.titleMode == 2) {
  164.                s = ((Applet)this).getParameter("title_row");
  165.             } else {
  166.                s = br.readLine();
  167.                if (s == null) {
  168.                   br.close();
  169.                   break;
  170.                }
  171.             }
  172.  
  173.             try {
  174.                if (i == 1 && this.titleMode != 0) {
  175.                   for(int j = 0; j < this.NCol - 1; ++j) {
  176.                      this.data[i][j] = "";
  177.                   }
  178.  
  179.                   ++i;
  180.                }
  181.  
  182.                for(int j = 0; j < this.NCol - 1; ++j) {
  183.                   int p = s.indexOf(",");
  184.                   this.data[i][j] = s.substring(0, p);
  185.                   s = s.substring(p + 1);
  186.                }
  187.  
  188.                this.data[i][this.NCol - 1] = s;
  189.             } catch (Exception var14) {
  190.             }
  191.  
  192.             ++i;
  193.          }
  194.       } catch (IOException e) {
  195.          System.out.println("data file read error !" + e);
  196.       }
  197.  
  198.       ((Container)this).setLayout((LayoutManager)null);
  199.       int[] wiMax = new int[this.NCol];
  200.  
  201.       for(int i = 0; i < this.NCol; ++i) {
  202.          wiMax[i] = 0;
  203.       }
  204.  
  205.       this.heMax = 0;
  206.  
  207.       for(int i = 0; i < this.data.length; ++i) {
  208.          for(int j = 0; j < this.NCol; ++j) {
  209.             Label ll = new Label(this.data[i][j]);
  210.             ((Component)ll).setVisible(false);
  211.             ((Container)this).add(ll);
  212.             if (this.titleMode != 0) {
  213.                Font f = ((Component)ll).getFont();
  214.                ((Component)ll).setFont(new Font("TimesRoman", 1, f.getSize()));
  215.             }
  216.  
  217.             if (((Component)ll).getPreferredSize().height > this.heMax) {
  218.                this.heMax = ((Component)ll).getPreferredSize().height;
  219.             }
  220.  
  221.             if (((Component)ll).getPreferredSize().width > wiMax[j]) {
  222.                wiMax[j] = ((Component)ll).getPreferredSize().width;
  223.             }
  224.  
  225.             ((Container)this).remove(ll);
  226.          }
  227.       }
  228.  
  229.       int wiPos = 0;
  230.       int hePos = 0;
  231.  
  232.       for(int i = 0; i < this.data.length; ++i) {
  233.          for(int j = 0; j < this.NCol; ++j) {
  234.             if (j == 0) {
  235.                wiPos = 0;
  236.             }
  237.  
  238.             Label l = new Label(this.data[i][j]);
  239.             if (i % 2 == 0) {
  240.                ((Component)l).setBackground(this.backColor2);
  241.             }
  242.  
  243.             String s = ((Applet)this).getParameter("columns_color" + Integer.toString(j + 1));
  244.             if (s != null) {
  245.                ((Component)l).setForeground(this.getColor("columns_color" + Integer.toString(j + 1)));
  246.             } else {
  247.                ((Component)l).setForeground(this.columnsColor);
  248.             }
  249.  
  250.             ((Container)this).add(l);
  251.             if (i == 0 && this.titleMode != 0) {
  252.                Font f = ((Component)l).getFont();
  253.                ((Component)l).setFont(new Font("TimesRoman", 1, f.getSize()));
  254.             }
  255.  
  256.             ((Component)l).setBounds(wiPos + this.space + this.border, hePos + this.border, ((Component)l).getPreferredSize().width, ((Component)l).getPreferredSize().height);
  257.             wiPos += wiMax[j] + this.wspace;
  258.             if (j == this.NCol - 1) {
  259.                hePos += this.heMax;
  260.             }
  261.          }
  262.       }
  263.  
  264.       ((Component)this).repaint();
  265.    }
  266.  
  267.    public void update(Graphics g) {
  268.       this.paint(g);
  269.    }
  270.  
  271.    public void paint(Graphics g) {
  272.       if (this.mode == 1) {
  273.          g.setColor(this.backColor2);
  274.  
  275.          for(int i = 0; i < this.data.length; i += 2) {
  276.             g.fillRect(0, i * this.heMax + this.border, this.field_0, this.heMax);
  277.          }
  278.  
  279.          if (this.border > 0) {
  280.             g.setColor(this.borderColor);
  281.  
  282.             for(int i = 0; i < this.border; ++i) {
  283.                g.drawRect(i, i, this.field_0 - 2 * i - 1, this.field_1 - 2 * i - 1);
  284.             }
  285.          }
  286.  
  287.       }
  288.    }
  289.  
  290.    public void stop() {
  291.    }
  292.  
  293.    public void getParameters() {
  294.       this.field_0 = ((Component)this).getSize().width;
  295.       this.field_1 = ((Component)this).getSize().height;
  296.       String s = ((Applet)this).getParameter("title_mode");
  297.       if (s != null) {
  298.          this.titleMode = Integer.parseInt(s);
  299.       }
  300.  
  301.       s = ((Applet)this).getParameter("skip_first_row");
  302.       if (s != null) {
  303.          this.skip = Integer.parseInt(s);
  304.       }
  305.  
  306.       if (this.getColor("background_color") != null) {
  307.          this.backColor = this.getColor("background_color");
  308.       }
  309.  
  310.       if (this.getColor("background_color2") != null) {
  311.          this.backColor2 = this.getColor("background_color2");
  312.          this.mode = 1;
  313.       }
  314.  
  315.       if (this.getColor("background_color") != null) {
  316.          this.backColor = this.getColor("background_color");
  317.       }
  318.  
  319.       if (this.getColor("columns_color") != null) {
  320.          this.columnsColor = this.getColor("columns_color");
  321.       }
  322.  
  323.       this.statusBarText = ((Applet)this).getParameter("status_bar_text");
  324.       this.link = ((Applet)this).getParameter("link");
  325.       s = ((Applet)this).getParameter("border");
  326.       if (s != null) {
  327.          this.border = Integer.parseInt(s);
  328.       }
  329.  
  330.       if (this.getColor("border_color") != null) {
  331.          this.borderColor = this.getColor("border_color");
  332.       }
  333.  
  334.       s = ((Applet)this).getParameter("columns_space");
  335.       if (s != null) {
  336.          this.wspace = Integer.parseInt(s);
  337.       }
  338.  
  339.    }
  340.  
  341.    private Color getColor(String param) {
  342.       String s = ((Applet)this).getParameter(param);
  343.       if (s != null) {
  344.          if (s.substring(0, 1).equals("#")) {
  345.             s = s.substring(1);
  346.             int i = Integer.parseInt(s, 16);
  347.             return new Color(i);
  348.          } else {
  349.             return null;
  350.          }
  351.       } else {
  352.          return null;
  353.       }
  354.    }
  355.  
  356.    public URL giveURL(String url) {
  357.       try {
  358.          if (url.toUpperCase().startsWith("HTTP")) {
  359.             return new URL(url);
  360.          } else if (url.toUpperCase().startsWith("FTP")) {
  361.             int p = url.indexOf(":");
  362.             int p2 = url.indexOf(":", p + 1);
  363.             if (p2 != -1) {
  364.                url = url.substring(0, p + 3) + URLEncoder.encode(url.substring(p + 3, url.length()));
  365.             }
  366.  
  367.             p = url.indexOf("%40");
  368.             if (p != -1) {
  369.                url = url.substring(0, p) + "@" + url.substring(p + 3, url.length());
  370.             }
  371.  
  372.             return new URL(url);
  373.          } else {
  374.             return new URL(((Applet)this).getCodeBase(), url);
  375.          }
  376.       } catch (MalformedURLException e) {
  377.          System.out.println(e);
  378.          return null;
  379.       }
  380.    }
  381.  
  382.    public Table() {
  383.       this.backColor = Color.white;
  384.       this.backColor2 = Color.blue;
  385.       this.columnsColor = Color.black;
  386.       this.titleMode = 0;
  387.       this.skip = 0;
  388.       this.border = 0;
  389.       this.borderColor = Color.black;
  390.       ((Component)this).addMouseListener(this);
  391.    }
  392.  
  393.    public void mouseClicked(MouseEvent e) {
  394.    }
  395.  
  396.    public void mouseEntered(MouseEvent e) {
  397.       if (this.statusBarText != null) {
  398.          ((Applet)this).showStatus(this.statusBarText);
  399.       }
  400.  
  401.       if (this.link != null) {
  402.          ((Component)this).setCursor(new Cursor(12));
  403.       }
  404.  
  405.    }
  406.  
  407.    public void mouseExited(MouseEvent e) {
  408.    }
  409.  
  410.    public void mousePressed(MouseEvent e) {
  411.       if (this.link != null) {
  412.          String target = ((Applet)this).getParameter("target");
  413.          if (target == null) {
  414.             target = "_blank";
  415.          }
  416.  
  417.          URL u = this.giveURL(this.link);
  418.          ((Applet)this).getAppletContext().showDocument(u, target);
  419.       }
  420.  
  421.    }
  422.  
  423.    public void mouseReleased(MouseEvent e) {
  424.    }
  425. }
  426.